package cn.scw.project.facility.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.facility.domain.netework.bean.FacPrintPriceAddReq;
import cn.scw.project.facility.domain.netework.bean.FacPrintPriceFacilityAddReq;
import cn.scw.project.facility.domain.netework.bean.FacPrintPriceFacilityFindReq;
import cn.scw.project.facility.domain.vo.FacPrintPriceResVo;
import cn.scw.project.facility.service.IFacPrintPriceFacilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备打印价格Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "设备打印价格")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/facility/print/price/facility")
public class FacPrintPriceFacilityController extends BaseController {
    @Autowired
    private IFacPrintPriceFacilityService facPrintPriceFacilityService;

    @ApiOperation("查询设备打印价格列表")
    //@PreAuthorize("@ss.hasPermi('facility:facility:list')")
    @GetMapping("/list/{code}")
    public TableDataInfo list(@PathVariable @ApiParam("设备编码") String code) {
        List<FacPrintPriceResVo> list = facPrintPriceFacilityService.selectFacPrintPriceFacilityList(code);
        return getDataTable(list);
    }

    @ApiOperation("根据打印类型查询打印价格")
    @GetMapping("/price")
    public AjaxResult list(FacPrintPriceFacilityFindReq req) {
        return AjaxResult.success(facPrintPriceFacilityService.selectByFacilityCodeAndTypeAndIsColoursAndIsDoubleFacedAndPaperNumber(req));
    }

    @ApiOperation("获取设备打印价格详细信息")
    //@PreAuthorize("@ss.hasPermi('facility:facility:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(facPrintPriceFacilityService.selectFacPrintPriceFacilityVoById(id));
    }

    @ApiOperation("新增设备打印价格")
    //@PreAuthorize("@ss.hasPermi('facility:facility:add')")
    @Log(title = "设备打印价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<FacPrintPriceFacilityAddReq> req) {
        return toAjax(facPrintPriceFacilityService.insertFacPrintPriceFacility(req));
    }

    @ApiOperation("修改设备打印价格")
    //@PreAuthorize("@ss.hasPermi('facility:facility:edit')")
    @Log(title = "设备打印价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(FacPrintPriceAddReq req) {
        return toAjax(facPrintPriceFacilityService.updateFacPrintPriceFacility(req));
    }

    @ApiOperation("删除设备打印价格")
    //@PreAuthorize("@ss.hasPermi('facility:facility:remove')")
    @Log(title = "设备打印价格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(facPrintPriceFacilityService.deleteFacPrintPriceFacilityByIds(ids));
    }
}
